#!/bin/bash
# 检查 build-essential 包是否未安装，如果是，则安装它
if ! dpkg -s build-essential > /dev/null 2>&1; then
    apt-get update -y
    apt-get install -y build-essential
fi
#检查 cmake 是否已安装
if ! command -v cmake >/dev/null 2>&1; then
    echo "cmake 未安装正在尝试安装"
    apt-get update -y
    apt-get install -y cmake
fi
# 获取当前脚本的绝对路径
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd $(dirname $SCRIPT_PATH)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    exit 1
fi
cd ../..
#git clone https://gitcode.com/sound/x265.git /opt/src/x265
# 生成临时文件
BUILD_DIR="/tmp/build/module_manager/debug/x265"
SOURCE_DIR=/opt/src/x265/source
#删除 临时文件
rm -rf $BUILD_DIR
cmake \
-D CMAKE_BUILD_TYPE=Debug \
-DENABLE_SHARED=OFF \
-DENABLE_CLI=OFF \
-DENABLE_ASM=ON \
-DCMAKE_CXX_FLAGS="-march=armv7-a" \
-DCMAKE_C_FLAGS="-march=armv7-a" \
-DCMAKE_INSTALL_PREFIX=/opt/install/x265/Release_3.4/armv7a-v8a \
-DCMAKE_C_COMPILER=/mnt/android_home/ndk/r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang \
-DCMAKE_CXX_COMPILER=/mnt/android_home/ndk/r21e/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++ \
-S $SOURCE_DIR -B $BUILD_DIR
# 检查构建是否成功
if [ $? -ne 0 ]; then
  echo "配置失败"
  exit 1
fi
cmake --build $BUILD_DIR -j$(nproc)
if [ $? -ne 0 ]; then
  echo "编译失败"
  exit 1
fi
cmake --install $BUILD_DIR
if [ $? -ne 0 ]; then
  echo "安装失败"
  exit 1
fi









